#!/usr/bin/env python

import sys, os, re

class stats:
  def __init__(self):
    self.acc = None
    self.racc = None
    self.bad = None
    self.tp = None
    self.fp = None
    self.tn = None
    self.fn = None
    self.rtp = None
    self.rfp = None
    self.rtn = None
    self.rfn = None

  def valid(self):
    if self.bad: return False
    if not self.acc: return False
    if not self.racc: return False
    return True

results = []
for file in os.listdir('.'):
  if not file[-4:] == ".csv": continue
  f = open(file, 'r')
  s = stats()
  s.file = file[:-4]
  for line in f:
    m = re.search('Accuracy (\d+(?:\.\d+)?)', line)
    if m:
      if not s.acc:
        s.acc = float(m.group(1))
      else:
        s.racc = float(m.group(1))
    m = re.search('Precision: (\d+(?:\.\d+)?|-nan)', line)
    if m and s.bad == None:
      if m.group(1) == '-nan':
        s.bad = True
      else:
        s.bad = False
        s.rec = float(m.group(1))
    m = re.search('TP: (\d+), FP: (\d+), TN: (\d+), FN: (\d+)', line)
    if m:
      if s.tp == None:
        s.tp = int(m.group(1))
        s.fp = int(m.group(2))
        s.tn = int(m.group(3))
        s.fn = int(m.group(4))
      else:
        s.rtp = int(m.group(1))
        s.rfp = int(m.group(2))
        s.rtn = int(m.group(3))
        s.rfn = int(m.group(4))
  results += [s]
  f.close()

results = sorted(results, lambda x,y: cmp(x.acc,y.acc))

for r in results:
  if r.valid() and re.search('_linear_hog_only', r.file):
    print "%s: Acc: %2.4f, R-Acc: %2.4f" % (r.file, r.acc, r.racc)
    print "TP: %i, FP: %i, RTP: %i" % (r.tp, r.fp, r.rtp)
    print "TN: %i, FN: %i, RTN: %i" % (r.tn, r.fn, r.rtn)
